//
//  SignUpViewController.swift
//  
//
//  Created by LiuXing on 2017/6/10.
//
//

import UIKit
import FirebaseAuth
import SVProgressHUD

class SignUpStep1ViewController: UIViewController {
    
    
    @IBOutlet weak var accountTextField: UITextField!
    @IBOutlet weak var passwordTextField: UITextField!
    @IBOutlet weak var nameTextField: UITextField!
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        title = "SIGNUP"
        navigationItem.rightBarButtonItem =  nextButtonItem
    }
    
    private lazy var nextButtonItem: UIBarButtonItem = {
        //        let backButton = UIBarButtonItem.crateBarButtonItem(imageName: "back", target: self, action: #selector(MainNavViewController.pop))
        let nextButtonItem = UIBarButtonItem(image: UIImage(named:"next"), style: .plain, target: self, action: #selector(nextButtonItemClick))
        nextButtonItem.tintColor = UIColor.white
        return nextButtonItem
    }()
    
    @objc private func nextButtonItemClick() {
        if accountTextField.text == "" {
            HudTool.shareInstance.showEorrorMessage(errorMessage: "please enter your email adress")
            return
        }
        if passwordTextField.text == "" {
             HudTool.shareInstance.showEorrorMessage(errorMessage: "please enter your email password")
            return
        }
//        HudTool.shareInstance.show()
        let sb = UIStoryboard(name: "LogInAndSignUp", bundle: nil)
        let vc = sb.instantiateViewController(withIdentifier: "SignUpStep2ViewController") as! SignUpStep2ViewController
        self.navigationController!.pushViewController(vc, animated: true)
//        Auth.auth().createUser(withEmail: accountTextField.text!, password: passwordTextField.text!) { (user, error) in
//            HudTool.shareInstance.dismiss()
//            print(user)
//            print(error)
//            if error == nil { // creat
//                UserAccountTool.shareIntance.account?.email = self.accountTextField.text
//                UserAccountTool.shareIntance.account?.password = self.passwordTextField.text
//                let sb = UIStoryboard(name: "LogInAndSignUp", bundle: nil)
//                let vc = sb.instantiateViewController(withIdentifier: "SignUpStep2ViewController") as! SignUpStep2ViewController
//                self.navigationController!.pushViewController(vc, animated: true)
//            } else {
//                HudTool.shareInstance.showEorrorMessage(errorMessage: "your email may not invild ")
//            }
//        }
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
